package com.design.YiTong.user.controller;

import com.design.YiTong.vo.user.LoginVo;
import com.design.YiTong.vo.user.RegisterVo;
import com.design.YiTong.common.result.Result;
import com.design.YiTong.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    @ApiOperation(value = "用户登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo){
        return Result.ok(userInfoService.loginUser(loginVo));
    }
    @ApiOperation(value = "用户注册")
    @PostMapping("register/{checkCode}")
    public Result rigister(@RequestBody RegisterVo registerVo,@PathVariable String checkCode){
        userInfoService.registerUser(registerVo,checkCode);
        return Result.ok();
    }
    @ApiOperation(value = "修改昵称")
    @GetMapping("changeName/{phone}/{nickName}")
    public Result changeName(@PathVariable String phone,@PathVariable String nickName){
        userInfoService.changeName(phone,nickName);
        return Result.ok();
    }
    @ApiOperation(value = "修改密码")
    @GetMapping("changePwd/{phone}/{pwd}/{checkCode}")
    public Result changepwd(@PathVariable String phone,@PathVariable String pwd,@PathVariable String checkCode){
        if(!userInfoService.changePwd(phone,pwd,checkCode)){
            return Result.fail();
        }
        return Result.ok();
    }
}
